﻿// ===============================================================================
// SchemaExtensions.cs
// EOS Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Schema.Extensions
{
    using EOS.Framework.Contracts.Schema;

    public static class SchemaExtensions
    {
        public static bool IsReference(this ColumnSchema columnToCheck)
        {
            bool isReference = false;
            foreach (ReferenceSchema reference in columnToCheck.Table.OutReferences)
            {
                foreach (ReferenceJoin join in reference.Joins)
                {
                    if (join.ParentColumn.Equals(columnToCheck))
                    {
                        isReference = true;
                        break;
                    }
                }
            }

            if (isReference == false)
            {
                foreach (ReferenceSchema reference in columnToCheck.Table.InReferences)
                {
                    foreach (ReferenceJoin join in reference.Joins)
                    {
                        if (join.ChildColumn.Equals(columnToCheck))
                        {
                            isReference = true;
                            break;
                        }
                    }
                }
            }

            return isReference;
        }


    }
}
